#include "watermarkgeneratorfactory.h"
#include "whitespacewatermarkgenerator.h"

namespace Wishmaster
{
	WatermarkGeneratorFactory::WatermarkGeneratorFactory() : Singleton<WatermarkGeneratorFactory>()
	{
		addTextWatermarkGenerator(TextWatermarkGeneratorPtr(new WhitespaceWatermarkGenerator));
	}

	WatermarkGeneratorFactory::~WatermarkGeneratorFactory()
	{
	}

	TextWatermarkGeneratorPtr WatermarkGeneratorFactory::createTextWatermark(const QString& id)
	{
		QMap<QString, TextWatermarkGeneratorPtr>::iterator it = m_textWatermarks.find(id);
		if(it == m_textWatermarks.end())
			return TextWatermarkGeneratorPtr();
		return it.value()->clone();
	}

	bool WatermarkGeneratorFactory::probeTextWatermark(const QString& input, QByteArray& result)
	{
		for(QMap<QString, TextWatermarkGeneratorPtr>::iterator it = m_textWatermarks.begin(); it != m_textWatermarks.end(); ++it)
		{
			if(it.value()->probe(input))
			{
				result = it.value()->decode(input);
				return true;
			}
		}
		return false;
	}

	void WatermarkGeneratorFactory::addTextWatermarkGenerator(const TextWatermarkGeneratorPtr& generator)
	{
		m_textWatermarks.insert(generator->id(), generator);
	}
}
